// 我的手牌
class myHandPoker extends egret.Sprite{
    public pointId:number;//保存位置ID
    private thisY:number;
    private cardMove:egret.Bitmap;
    public constructor(){
        super();
        this.addEventListener(egret.Event.ADDED_TO_STAGE,this.onAddEd,this);
    }
    private onAddEd(){
        this.cardMove = MyLibrary.createBitmapByName("cardPoint_png");
        this.cardMove.anchorOffsetX = this.cardMove.width/2;
        this.addChild(this.cardMove);
        this.cardMove.y = -this.cardMove.height;
        this.cardMove.visible = false;
        egret.Tween.get(this.cardMove,{"loop":true}).to({y:-this.cardMove.height-10},500).to({y:-this.cardMove.height},500);

        this.init();
        this.once(egret.Event.REMOVED_FROM_STAGE,this.onRemove,this);
    }
    private onRemove(){
        egret.Tween.removeTweens(this.cardMove);
        this.removeChild(this.cardMove);
        this.cardMove = null;
        this.clearLongPressTimer();
        this.removeEventListener(egret.TouchEvent.TOUCH_BEGIN,this.onDown,this);
        StageData.MainObj.removeEventListener(egret.TouchEvent.TOUCH_END,this.onUp,this);
        this.removeEventListener(egret.TouchEvent.TOUCH_TAP,this.onClick,this);
        StageData.MainObj.removeEventListener(Events.STAGE_SIZE,this.onStageSize,this);
    }

    public handPokerBg:egret.Sprite = new egret.Sprite();//手牌容器
    public qishouhuPokerBg:egret.Sprite = new egret.Sprite();//手牌容器
    private winPokerBg:egret.Sprite = new egret.Sprite();//赢牌容器
    private handPokerList:Array<any> = new Array();//牌对象
    private winPokerList:Array<any> = new Array();//赢牌对象
    private outPoker_y:number = -50;//出牌界线值
    private choosePoker_y:number = -10;//选择牌后改变值

    private init(){
        this.thisY = this.y;
        this.winPokerBg.x = 10;
        this.winPokerBg.y = 20;
        this.addChild(this.winPokerBg);
        this.addChild(this.handPokerBg);
        this.qishouhuPokerBg.x = 100
        this.addChild(this.qishouhuPokerBg);
        this.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.onDown,this);
        StageData.MainObj.addEventListener(egret.TouchEvent.TOUCH_END,this.onUp,this);
        this.addEventListener(egret.TouchEvent.TOUCH_TAP,this.onClick,this);
        StageData.MainObj.addEventListener(Events.STAGE_SIZE,this.onStageSize,this);        
    }
    private downCard:Boolean = true;//是否可以点击牌
    private onClick(e:egret.TouchEvent){
        console.log('e.target.name', e.target.name);
        if(e.target.name.split("_")[0] == "poker"){
            let ifLongPress:boolean = false;
            if(this.downCard){
                if(e.target.y == this.choosePoker_y){
                    e.target.y = 0;
                    // StageData.soundObj.soundSinglePlay("isClick");
                }else{
                    e.target.y = this.choosePoker_y;
                    // StageData.soundObj.soundSinglePlay("click");
                }
            }            
            this.downCard = true;
        }
    }

    private DragObj:handPoker;
    private LongPressTimer; 
    private doublePressTimer;
    private isLongPress:boolean;//是否长按
    private doubleClick:boolean;//是否双击
    private pokerNum:number = 0;//添加过的牌数量
    //private lastgetcard:handPoker;//最后抓的一张牌

    //清除所有牌
    public clearAllPoker(){
        for(var i=this.handPokerBg.numChildren;i>0;i--){
            this.handPokerBg.removeChildAt(i-1);
        }
        for(var i=this.winPokerBg.numChildren;i>0;i--){
            this.winPokerBg.removeChildAt(i-1);
        }
        this.pokerNum = 0;
        this.handPokerList = [];
    }

    //通过名字获取数据
    private getPokerData(_name:string):any{
        var lsData:any;
        for(var i=0;i<this.handPokerList.length;i++){
            if(this.handPokerList[i].objmc.name == _name){
                lsData = this.handPokerList[i].data;
                break;
            }
        }
        return lsData;
    }
    private onDown(e:egret.TouchEvent){
        console.log('e.target.name', e.target.name);
        if (e.target.baotingDi && e.target.baotingDi.visible) {
            return 
        }
        if(e.target.name.split("_")[0] == "poker"){
            this.DragObj = e.target;  
            //双击检测
            if(this.doubleClick){
                //出牌                
                this.DragObj.alpha = 0.5;
                this.dispatchEventWith(PokerEvent.OUT_POKER,false,
                {x:this.DragObj.x,y:this.DragObj.y,localX:this.handPokerBg.x+this.DragObj.x,doubleClick:true,value:this.getPokerData(this.DragObj.name)});
                return;
            }
            this.doubleClick = true;
            this.doublePressTimer = egret.setTimeout(()=>{
               egret.clearTimeout(this.doublePressTimer);
               this.doublePressTimer = null;
               this.doubleClick = false;
            },this,300);
            
            //长按检测
            this.LongPressTimer = egret.setTimeout(()=>{
                this.clearLongPressTimer();
                this.isLongPress = true; 
                this.downCard = false;//长按后不能点击牌
                this.dispatchEventWith(PokerEvent.HAVE_POKER_START,false,this.getPokerData(this.DragObj.name));
                this.DragObj.removeEventListener(egret.TouchEvent.TOUCH_MOVE,this.onMove,this);
               // alert("长按");
                return;
            },this,500);

            //拖牌
            this.DragObj.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.onMove,this);
        }
    }
    private onMove(e:egret.TouchEvent){
        this.DragObj.removeEventListener(egret.TouchEvent.TOUCH_MOVE,this.onMove,this);        
        this.clearLongPressTimer();
        //出牌
        this.DragObj.alpha = 0;
        this.dispatchEventWith(PokerEvent.OUT_POKER,false,
                {x:this.DragObj.x,y:this.DragObj.y,doubleClick:false,value:this.getPokerData(this.DragObj.name)});
    }
    private onUp(e:egret.TouchEvent){
        if(this.DragObj){
            this.DragObj.removeEventListener(egret.TouchEvent.TOUCH_MOVE,this.onMove,this);
            this.DragObj.alpha = 1;            
            if(this.isLongPress){
                this.isLongPress = false;
                this.dispatchEventWith(PokerEvent.HAVE_POKER_END);
            }            
            this.DragObj = null;
            this.clearLongPressTimer();
        }
    }

    //清除长按计时器
    private clearLongPressTimer(){
        if(this.LongPressTimer){
            egret.clearTimeout(this.LongPressTimer);
            this.LongPressTimer = null;
        }
    }

    public clearThis(){
        for(var i=this.handPokerBg.numChildren;i>0;i--){
            this.handPokerBg.removeChildAt(i-1);
        }
        for(var i=this.winPokerBg.numChildren;i>0;i--){
            this.winPokerBg.removeChildAt(i-1);
        }
        this.handPokerList = [];
        this.winPokerList = [];
        this.cardMove.visible = false;
    }
    /****摊牌-名牌****/
    public openDeal(msg,lastGetCard){
        if(!msg) return;     
        for(var i=this.handPokerBg.numChildren;i>0;i--){
            this.handPokerBg.removeChildAt(i-1);
        }
        this.handPokerList = [];
        let lslast:any;
        for(var i:number=0;i<msg.length;i++){
            if(lastGetCard&&!lslast&&msg[i].cardIndex==lastGetCard.cardIndex){
                lslast = lastGetCard;
            }else{
                this.addhandPokerDeal(msg[i].suitType,msg[i].count,msg[i].cardIndex,false);
            } 
        }//{"cardIndex":23,"count":4,"suitType":"T"}//{flower:msg.suitType,value:msg.count,id:msg.cardIndex}
        if(this.winPokerBg.numChildren<1&&this.handPokerList.length>0){
          this.handPokerBg.x = (StageData.W - (this.handPokerList[0].objmc.width*this.handPokerList.length))/2+10;
        }        
        this.y = StageData.H - (160*this.scaleX);
        //刷新牌排列位置
        this.pokerSort();
        this.onStageSize();
        //最后抓的牌
        if(lslast&&lastGetCard){
            //this.cardMove.visible = true;
            this.addhandPokerDeal(lastGetCard.suitType,lastGetCard.count,lastGetCard.cardIndex,true);
        }                
    }
    public addhandPokerDeal(flower:string,value:string,id:number,grab:boolean=false,anction:boolean=false){
        console.log('addhandPokerDeal');
        if(flower&&value&&id){            
            let pokerMc:handPokerPlay = new handPokerPlay(4);
            pokerMc.name = "poker_"+this.pokerNum;//this.handPokerList.length;
            this.pokerNum ++;
            pokerMc.setContent(flower+"_"+value+"_png");
            this.handPokerBg.addChild(pokerMc)
            pokerMc.baotingDi.visible = false
            
            this.cardMove.visible = false;
            if(grab){
                pokerMc.x = pokerMc.width*this.handPokerList.length+10;
                this.cardMove.visible = true;
                this.cardMove.x = this.handPokerBg.x + pokerMc.x + (pokerMc.width/2);
                // if(anction){
                //     pokerMc.y =-pokerMc.height;  
                //     pokerMc.scaleX = pokerMc.scaleY = 0.6;
                //     pokerMc.rotation = -30;
                //     // StageData.soundObj.soundSinglePlay("tuopan");               
                //     egret.Tween.get(pokerMc).to({y:0,scaleX:1,scaleY:1,rotation:0},300,egret.Ease.quadOut).call(()=>{
                //         // StageData.soundObj.soundSinglePlay("getCard");
                //         egret.Tween.removeTweens(pokerMc); 
                //     });
                // }
                this.handPokerBg.width = pokerMc.width*(this.handPokerList.length+1);
                pokerMc.touchEnabled = true;
                this.handPokerList.push({objmc:pokerMc,data:{flower:flower,value:value,id:id}});
                this.onStageSize();
            }else{                
                pokerMc.x = pokerMc.width*this.handPokerList.length;

                this.handPokerBg.width = pokerMc.width*(this.handPokerList.length+1);
                pokerMc.touchEnabled = true;
                this.handPokerList.push({objmc:pokerMc,data:{flower:flower,value:value,id:id}});
            }
        }
    }
    //****end*** */
    //添加手牌
    public handpokerData: any
    private lastMsg: any
    private lastlastGetCard: any
    public addHandPoker(msg,lastGetCard){
        if (_.isEqual(this.lastMsg, msg) && _.isEqual(this.lastlastGetCard, lastGetCard)) {
            console.log('addHandPoker isEqual');
            return
        } else {
            this.lastMsg = msg
            this.lastlastGetCard = lastGetCard
        }
        console.log('addHandPoker');
       // alert(JSON.stringify(msg));
        if(!msg) return;     
        for(var i=this.handPokerBg.numChildren;i>0;i--){
            this.handPokerBg.removeChildAt(i-1);
        }
        this.handPokerList = [];
        this.handpokerData = msg
        let lslast:any;
        for(var i:number=0;i<msg.length;i++){
            if(lastGetCard&&!lslast&&msg[i].cardIndex==lastGetCard.cardIndex){
                lslast = lastGetCard;
                //this.cardMove.visible = true;
                //alert("aa");
            }else{
                this.addSinglePoker(msg[i].suitType,msg[i].count,msg[i].cardIndex,false);
            } 
        }//{"cardIndex":23,"count":4,"suitType":"T"}//{flower:msg.suitType,value:msg.count,id:msg.cardIndex}
        if(this.winPokerBg.numChildren<1&&this.handPokerList.length>0){
          this.handPokerBg.x = (StageData.W - (this.handPokerList[0].objmc.width*this.handPokerList.length))/2+10;
        }        
        this.y = StageData.H - (160*this.scaleX);
        //刷新牌排列位置
        this.pokerSort();
        this.onStageSize();
        //最后抓的牌
        if(lslast&&lastGetCard){
            //this.cardMove.visible = true;
            this.addSinglePoker(lastGetCard.suitType,lastGetCard.count,lastGetCard.cardIndex,true);
        }                
        //alert("手牌PK："+thisW+":"+StageData.W);
    }
    
    //设置接的手牌
    //private lastCardData:any;
    //添加单张牌(花色，值，ID，是否抓牌)
    public addSinglePoker(flower:string,value:string,id:number,grab:boolean=false,anction:boolean=false){
        if(flower&&value&&id){            
            let pokerMc:handPoker = new handPoker();
            pokerMc.name = "poker_"+this.pokerNum;//this.handPokerList.length;
            this.pokerNum ++;
            pokerMc.setContent(flower+"_"+value+"_png");
            this.handPokerBg.addChild(pokerMc);
            
            this.cardMove.visible = false;
            console.log('addSinglePoker', grab);
            const tingRolldice = GameData.myUserData.tingRolldice || GameData.myUserData.listenCard === 3
            if(grab){
                pokerMc.x = pokerMc.width*this.handPokerList.length+10;
                this.cardMove.visible = true;
                this.cardMove.x = this.handPokerBg.x + pokerMc.x + (pokerMc.width/2);
                // if(anction){
                //     pokerMc.y =-pokerMc.height;  
                //     pokerMc.scaleX = pokerMc.scaleY = 0.6;
                //     pokerMc.rotation = -30;
                //     // StageData.soundObj.soundSinglePlay("tuopan");               
                //     egret.Tween.get(pokerMc).to({y:0,scaleX:1,scaleY:1,rotation:0},300,egret.Ease.quadOut).call(()=>{
                //         // StageData.soundObj.soundSinglePlay("getCard");
                //         egret.Tween.removeTweens(pokerMc); 
                //     });
                // }
                this.handPokerBg.width = pokerMc.width*(this.handPokerList.length+1);
                pokerMc.touchEnabled = true;
                if (pokerMc.baotingDi) {
                    pokerMc.baotingDi.visible = tingRolldice      
                }   
                this.tingRolldice(tingRolldice)
                this.handPokerList.push({objmc:pokerMc,data:{flower:flower,value:value,id:id}});
                this.onStageSize();
            }else{                
                pokerMc.x = pokerMc.width*this.handPokerList.length;

                this.handPokerBg.width = pokerMc.width*(this.handPokerList.length+1);
                pokerMc.touchEnabled = true;
                this.handPokerList.push({objmc:pokerMc,data:{flower:flower,value:value,id:id}});
                if (pokerMc.baotingDi) {
                    pokerMc.baotingDi.visible = tingRolldice      
                }
            }
        }
    }
    //删除一张牌
    public deleteSinglePoker(id:number){
        this.cardMove.visible = false;
        if(!id) return;
        for(var i=0;i<this.handPokerList.length;i++){
            if(this.handPokerList[i].data.id == id){
                this.handPokerBg.removeChild(this.handPokerList[i].objmc);
                this.handPokerList.splice(i,1);
                //刷新牌排列位置
                this.pokerSort();
                this.onStageSize();
                break;
            }
        }
        for(var i=0;i<this.handPokerList.length;i++){
              this.handPokerList[i].objmc.y = 0;
        }        
    }
    //删除相同指定的手牌
    public deleteAppointPoker(flower:string,value:string,num:number = 9999){
        if(flower&&value){
            var newArr:Array<any>=new Array();  
            var deleteNumber:number = 0;          
             for(var i=0;i<this.handPokerList.length;i++){
                if(this.handPokerList[i].data.flower == flower&&this.handPokerList[i].data.value == value){
                    if(deleteNumber<num){
                        this.handPokerBg.removeChild(this.handPokerList[i].objmc);
                        deleteNumber ++;                        
                    }else{
                        newArr.push(this.handPokerList[i]);
                    }            
                }else{
                     //this.handPokerList.splice(i,1);
                    //刷新牌排列位置
                    newArr.push(this.handPokerList[i]);           
                }
            }
            this.handPokerList = newArr;
            this.pokerSort();
            this.onStageSize();
        }
    }
    //牌值排序
    public pokerArrayAscending(){         
        var lsArray:Array<any> = this.handPokerList.slice();
        var newArray:Array<any> = new Array();//排列红中
        /*for(var f:number=0;f<lsArray.length;f++){
            //alert("L:"+lsArray[f].data.id);
            if(lsArray[f].data.id == 31){
               // alert("s:"+lsArray.length);
                newArray.push(lsArray[f]);
                lsArray.splice(f,1);
            }
        }*/
        var i:number=lsArray.length-1, j:number, temp:any;
        for(var m:number=0; m<lsArray.length; m++){  
            for(var n:number=lsArray.length-1; n > m; n--){  
                 if(lsArray[n].data.id!=32&&lsArray[n-1].data.id > lsArray[n].data.id){
                     temp = lsArray[n-1];         
                     lsArray[n-1] = lsArray[n];                                 
                     lsArray[n] = temp;
                 }  
            }  
        }  
        /*for(var k=0;k<newArray.length;k++){
            lsArray.unshift(newArray[k]);
        }*/
        this.handPokerList = lsArray;
    }

    //手牌位置排序
    private pokerSort(){
        //牌值排序
        this.pokerArrayAscending();
        //位置排序
        for(var i=0;i<this.handPokerList.length;i++){          
            this.handPokerList[i].objmc.x = this.handPokerList[i].objmc.width*i;
            this.handPokerList[i].y = 0;
        }        
    }
    private lengthBig:boolean = false;
    private onStageSize(){
        /*for(var i=0;i<this.winPokerList.length;i++){
            this.winPokerList[i].x = (this.winPokerList[i].width+5)*i;
        }*/

        let lsx; 
        if(this.winPokerBg.numChildren>0){
            lsx = this.winPokerBg.x + this.winPokerBg.width +5;
        }else{
            lsx = 5;
        }/*else{
            lsx = (StageData.W - (this.handPokerList[0].objmc.width*this.handPokerList.length))/2
        }*/
        this.handPokerBg.x = lsx;

        /*if(this.handPokerList&&this.handPokerList.length>0){
            let thisW:number = (this.handPokerList[0].objmc.width*15);
            this.scaleX = this.scaleY = (StageData.W/(thisW+20));
        }*/
        this.y = StageData.H - (160*this.scaleX);
        //console.log("\n\n手牌Y:"+this.y);
    }
    public winPokerUpdateListCount: number = 0
    private lastWinPokerList = []
    //刷新赢牌列表-碰牌/杠(花色，值，ID，赢牌的碰杠类型)
    public winPokerUpdateList(pokerList:Array<any>){
        console.log('this.lastWinPokerList', this.lastWinPokerList);
        console.log('pokerList', pokerList);
        const hasAngang = pokerList.some(poker => poker.actionType === 'AN_GANG')
        if (_.isEqual(this.lastWinPokerList, pokerList) && !hasAngang) {
            console.log('winPokerUpdateList isEqual');
            return 
        } else {
            this.lastWinPokerList = pokerList
        }
        for(var i=0;i<this.winPokerList.length;i++){
            if (this.winPokerList[i].parent) {
                this.winPokerBg.removeChild(this.winPokerList[i]);
            }
        }
        this.winPokerList = [];
        this.winPokerBg.width = 0;
        // StageData.GameRoot.clew("winPoker0："+this.winPokerList.length+" - "+this.winPokerBg.numChildren);
        
        console.log('pokerList', pokerList);
        for(var i=0;i<pokerList.length;i++){
            const id = pokerList[i].actionCode
            if (id === 7) {
                // this.qishouhula(pokerList[i])
                continue 
            }
            // this.winPoker(pokerList[i].actionCard.suitType,pokerList[i].actionCard.count,pokerList[i].actionCode,GameData.winPokerCode[pokerList[i].actionCode]);
            if (!pokerList[i].actionCard) {
                return
            }
            const flower = pokerList[i].actionCard.suitType
            const value = pokerList[i].actionCard.count
            const type = GameData.winPokerCode[pokerList[i].actionCode]
            if (type === 'hu') {
                continue
            }
            let lsobj:winPENG = new winPENG();
            lsobj.name = flower+value+"_"+type;
            const chidepai = pokerList[i].actionCards ? pokerList[i].actionCards[0].count : null
            lsobj.setContent(flower+"_"+value+"_png",type, chidepai);
            //lsobj.x = (lsobj.width+10)*this.winPokerBg.numChildren;
            this.winPokerBg.addChild(lsobj);
            this.winPokerList.push(lsobj);
            this.winPokerBg.width = (lsobj.width+10)*this.winPokerBg.numChildren;
         }
        for(var i=0;i<this.winPokerList.length;i++){
            this.winPokerList[i].x = (this.winPokerList[i].width+10)*i;
        }
        this.onStageSize();
        this.y = StageData.H - (160*this.scaleX);
       //StageData.GameRoot.clew("winPoker："+this.winPokerList.length+" - "+this.winPokerBg.numChildren);
       //this.onStageSize();
    }
    // public qishouhula(data) {
    //     this.winPokerBg.visible = false
    //     const user = GameData.userData.find(user => user.seatIndex === data.seatIndex)
    //     console.log('user', user);
    // }
    //赢牌-碰牌/杠(花色，值，ID，赢牌的碰杠类型)
    public winPoker(flower:string,value:string,id:number,type:string){
        console.log('winPoker!!!');
        if(flower&&value){        
            if(type!="peng"&&type!="chi"){
                //清除已经碰了的相同牌  
                for(var i=0;i<this.winPokerList.length;i++){
                    if(this.winPokerList[i].name == flower+value+"_peng"){
                        this.winPokerBg.removeChild(this.winPokerList[i]);
                        this.winPokerBg.width = (this.winPokerList[i].width+10)*this.winPokerBg.numChildren;
                        this.winPokerList.splice(i,1);
                    }
                }
            }
            
            let lsobj:winPENG = new winPENG();
            lsobj.name = flower+value+"_"+type;
            lsobj.setContent(flower+"_"+value+"_png",type);
            //lsobj.x = (lsobj.width+10)*this.winPokerBg.numChildren;
            this.winPokerBg.addChild(lsobj);
            this.winPokerList.push(lsobj);
            this.winPokerBg.width = (lsobj.width+10)*this.winPokerBg.numChildren;
            if(type == "peng"){
                this.deleteAppointPoker(flower,value,2);//删除相同手牌2张
            }else if(type == "gang"||type == "gonggang"||type == "angang"){
                this.deleteAppointPoker(flower,value);//删除所有相同手牌
            }
            else if(type == "chi" && GameData.lastOutPoker){
                console.log('GameData.lastOutPoker', GameData.lastOutPoker);
                for (let i = parseInt(value) - 1; i < parseInt(value) + 1; i++) {
                    if (i !== GameData.lastOutPoker.value) {
                        console.log('删除吃的手牌', flower, i);
                        this.deleteAppointPoker(flower,i + '',1)
                    } 
                }
                GameData.lastOutPoker = null
                // this.deleteAppointPoker(flower,parseInt(value) - 1 + '',1);//删除前一张
                // this.deleteAppointPoker(flower,parseInt(value) - 1 + '',1);//删除后一张
            }
            this.winPokerUpdateListCount++
            for(var i=0;i<this.winPokerList.length;i++){
                this.winPokerList[i].x = (this.winPokerList[i].width+10)*i;
            }
            this.onStageSize();
        }        
        this.y = StageData.H - (160*this.scaleX);
    }
    //是否暂停操作
    public isPause(value:boolean = true){
        if(value){
            this.touchEnabled = false;
            this.touchChildren = false;            
        }else{
            this.touchEnabled = true;
            this.touchChildren = true;
        }        
    }
    //获取是否可操作状态http://lefantian.jiahuagame.com/game-lobby/login/weiXin/0
    public get getPause():boolean{
        return this.touchEnabled;
    }

    public qishouhula(msg) {
        console.log('qishouhulamy');
        this.handPokerBg.visible = false
        this.qishouhuPokerBg.removeChildren()
        // const type = msg.action.actionCardMap[0].type
        const showAll = msg.action.actionCardMap.some(map => map.type === 3 || map.type === 4)
        const notShowToAllData = msg.action.actionCardMap.filter(map => map.type === 1 || map.type === 2)
        console.log('showAll', showAll);
        if (showAll) {
            this.handpokerData.forEach((data, index) => {
                // const {suitType, count, cardIndex} = data
                const pai = new TanpaiMy()
                pai.x = index * pai.width
                pai.setData(data)
                this.qishouhuPokerBg.addChild(pai)
                setTimeout(() => {
                    this.qishouhuPokerBg.removeChildren()
                    this.handPokerBg.visible = true
                }, 5000)
            })
        } else {
            // this.handpokerData.forEach((data, index) => {
            //     // const {suitType, count, cardIndex} = data
            //     const pai = new TanpaiMy()
            //     pai.x = index * pai.width
            //     pai.setData(data)
            //     this.qishouhuPokerBg.addChild(pai)
            //     setTimeout(() => {
            //         this.qishouhuPokerBg.removeChildren()
            //         this.handPokerBg.visible = true
            //     }, 300000)
            // })
            notShowToAllData.forEach((notshowtoAll, index) => {
                setTimeout(() => {
                    notshowtoAll.cards.forEach((data, index2) => {
                        // const {suitType, count, cardIndex} = data
                        const pai = new TanpaiMy()
                        pai.x = index2 * pai.width
                        pai.setData(data)
                        this.qishouhuPokerBg.addChild(pai)
                        setTimeout(() => {
                            // 展示完以后就移除 显示正常手牌  如果有下一种胡牌则移除子牌
                            if (index === notShowToAllData.length - 1) {
                                this.qishouhuPokerBg.removeChildren()
                                this.handPokerBg.visible = true 
                            } else {
                                this.qishouhuPokerBg.removeChildren()
                            }
                        }, 3500)
                    })
                    if (notshowtoAll.cards.length < GameData.myUserData.handCount) {
                        const addBackNum = GameData.myUserData.handCount - notshowtoAll.cards.length
                        for (let i = 0; i < addBackNum; i++) {
                            let pai = new TanpaiMy()
                            pai.x = (i + notshowtoAll.cards.length - 1) * pai.width
                            pai.setBack()
                            this.qishouhuPokerBg.addChild(pai)
                        }
                    }
                }, index * 4000)
            })
        }
    }

    public tingRolldice(tingle: boolean = false) {
        console.log('tingle', tingle);
        GameData.tingle = tingle
        setTimeout(() => {
            this.handPokerList.forEach((hand, index) => {
                if (hand.objmc.baotingDi) {
                    if (index === this.handPokerList.length - 1 && GameData.outPokerIndex === GameData.mySeatIndex) {
                        hand.objmc.baotingDi.visible = false                
                    } else {
                        hand.objmc.baotingDi.visible = tingle
                        // this.isPause(tingle)  
                        // if (tingle && index !== this.handPokerList.length - 1) {
                        //     hand.touchEnabled = false
                        // }  else {
                        //     hand.touchEnabled = true
                        // }                 
                    }
                }
            })
        }, 0)
        // this.handPokerBg.$children.forEach((child: any) => {
        //     console.log('child', child);
        //     // child.setGray(tingle)
        //     child.baotingDi.visible = tingle
        //     console.log('child.baotingDi.visible', child.baotingDi.visible);
        // })
    }
}